#!/bin/bash

mvn clean package -Dmaven.test.skip=true

chmod 777 docs/install/config.sh
docs/install/config.sh


array=("$@")
for item in "${array[@]}"; do
    if [ "$item" == "merchant" ]; then
        echo "发布jeepay-merchant开始"
        docker rmi -f jeepay/jeepay-merchant
        cd jeepay-merchant/
        docker build --no-cache -t jeepay/jeepay-merchant .
        docker stop jeepaymerchant
        docker rm jeepaymerchant

        docker run -itd --name jeepaymerchant --restart=always --network=jeepay-net \
        -p 9218:9218 \
        -v /etc/localtime:/etc/localtime:ro \
        -v $rootDir/service/logs:/jeepayhomes/service/logs \
        -v $rootDir/service/uploads:/jeepayhomes/service/uploads \
        -v $rootDir/service/configs/merchant/application.yml:/jeepayhomes/service/app/application.yml \
        -d jeepay/jeepay-merchant

        cd ../
        echo "发布jeepay-merchant结束"
    elif [ "$item" == "manager" ]; then
      echo "发布jeepay-manager开始"
      docker rmi -f jeepay/jeepay-manager
      cd jeepay-manager/
      docker build --no-cache -t jeepay/jeepay-manager .
      docker stop jeepaymanager
      docker rm jeepaymanager

      docker run -itd --name jeepaymanager --restart=always --network=jeepay-net \
      -p 9217:9217 \
      -v /etc/localtime:/etc/localtime:ro \
      -v $rootDir/service/logs:/jeepayhomes/service/logs \
      -v $rootDir/service/uploads:/jeepayhomes/service/uploads \
      -v $rootDir/service/configs/manager/application.yml:/jeepayhomes/service/app/application.yml \
      -d jeepay/jeepay-manager

      cd ../
      echo "发布jeepay-manager结束"
    elif [ "$item" == "payment" ]; then
      echo "发布jeepay-payment开始"
      docker rmi -f jeepay/jeepay-payment
      cd jeepay-payment/
      docker build --no-cache -t jeepay/jeepay-payment .
      docker stop jeepaypayment
      docker rm jeepaypayment

      docker run -itd --name jeepaypayment --restart=always --network=jeepay-net \
      -p 9216:9216 \
      -v /etc/localtime:/etc/localtime:ro \
      -v $rootDir/service/logs:/jeepayhomes/service/logs \
      -v $rootDir/service/uploads:/jeepayhomes/service/uploads \
      -v $rootDir/service/configs/payment/application.yml:/jeepayhomes/service/app/application.yml \
      -d jeepay/jeepay-payment

      cd ../
      echo "发布jeepay-payment结束"
    fi
done







